#include<iostream>
#include<algorithm>
using namespace std;
void show(int** _a,int n)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cout << _a[i][j] << " ";
        }
        cout << endl;
    }
}
int main()
{
    int n;
    cin >> n;
    int** A = new int* [n];//创建二维数组用来装边和点的信息
    int** P = new int* [n];//创建二维数组，溯源
    for (int i = 0; i < n; i++)
    {
        A[i] = new int[n];
        P[i] = new int[n];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> A[i][j];//输入数组元素,不可达输入999
            if (A[i][j] != 0 && A[i][j] != 9999)
            {
                P[i][j] = i;
            }
            else P[i][j] = -1;
        }
    }
    for (int k = 0; k < n; k++)
    {
        for (int i = 0; i < n; i++)
        {
            for (int j = 0 ; j < n; j++)
            {
                if (A[i][j] > A[i][k] + A[k][j])
                {
                    A[i][j] = A[i][k] + A[k][j];
                    P[i][j] = k;
                }
            }
        }
    }
    // show(A, n);
    // show(P, n);
    int source, dis;
    string io;
    cin >> source >> dis;
    if (P[source][dis] == -1)  cout << "can't reach!" << endl;
    else
    {
        cout<<"最短路径值为："<<A[source][dis]<<endl;
        io += (dis + 48);
        io += 'v';
        dis = P[source][dis];
        while (P[source][dis] != -1)
        {
            io += (dis + 48);
            io += 'v';
            dis = P[source][dis];
        }
        io += (source + 48);
        io += 'v';
        reverse(io.begin(), io.end());
        cout << io;
        cout <<endl;
    }
}